package com.mallcai.bigdata.ladon.controller.report;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mallcai.bigdata.ladon.controller.report.form.SqlRunLogForm;
import com.mallcai.bigdata.ladon.dpl.entity.report.SqlRunLog;
import com.mallcai.bigdata.ladon.service.report.ISqlRunLogService;
import com.mallcai.bigdata.ladon.vo.MyPageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 报表运行日志
 * Created by oneape<oneape15@163.com>
 * Created 2019-07-15 20:07.
 * Modify:
 */
@RequestMapping("/report/log")
@RestController
public class SqlRunLogController {

    @Autowired
    private ISqlRunLogService iSqlRunLogService;

    @RequestMapping("/getByPage")
    public MyPageInfo getByPage(@RequestBody @Validated SqlRunLogForm form) {
        PageHelper.startPage(form.getCurrentPage(), form.getPageSize());
        List<SqlRunLog> logs = iSqlRunLogService.getByParams(form.getParams());
        PageInfo<SqlRunLog> pageInfo = new PageInfo<>(logs);

        return new MyPageInfo<>(pageInfo);
    }

    @RequestMapping("/detail")
    public SqlRunLog getDetail(@RequestBody @Validated(value = SqlRunLogForm.IdCheck.class) SqlRunLogForm form) {
        return iSqlRunLogService.getById(form.getLogId());
    }
}
